$(function(){
	var expertId = null;

	//判断是否登陆
	if(app.getItem('userId') !='' && app.getItem('userId') != null){
		function loadData(){
			this.data={}
			this.init();
		}
	}else{
		Prompt.show("用户没有登录或者登录失效了！");
        app.go('login.html');
	}


	loadData.prototype.init=function(){
		var _this=this;
		getExpertInit();
		
	}

	//发送验证码
    function getExpertInit() {

    	var expertData = {
    		userToken:app.getItem('userToken'),
            userId:app.getItem('userId')
    	}

        app.post( app.url.api_base+"expert/isInfoAll.do", expertData,
            function(req) {
            	if(req.code==0){
            		var returnData=req.data;
            		expertId=returnData.id;
            		if (returnData.initFlag==0) {
            			$('#xieyineirong').modal('show');
            		} else if (returnData.status==0) {
            			Prompt.show("请先完成基本信息填写!",'提示',function(){});
						app.go('BaseInfo.html');
            		}
            	}
            },true);
    }

    function updateExpertInit() {
    	var expertData = {
    		userToken:app.getItem('userToken'),
            userId:app.getItem('userId'),
            id:expertId
    	}

        app.post( app.url.api_base+"expert/updateExpertInit.do", expertData,
            function(req) {
            	if(req.code==0){
            		app.go('BaseInfo.html');
            	}
            },true);
    }

    //协议同意
    $(document).on('click','.btnagree' ,function(){
    	
    	$('#xieyineirong').modal('hide');
    	updateExpertInit();
    });

    //协议不同意
    $(document).on('click','.btnnotagree' ,function(){
    	$('#xieyineirong').modal('hide');
        deleteUser();
    	app.go('login.html');
    });

    function deleteUser() {
        var expertData = {
            userToken:app.getItem('userToken'),
            userId:app.getItem('userId')
        }

        app.post( app.url.api_base+"login/userDeletedForNotApply.do", expertData,
            function(req) {},true);
    }

	new loadData();
})